package com.lg.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings("unchecked")
public class Criteria {
	
	protected List criteriaWithoutValue;
	protected List criteriaWithSingleValue;
	protected List criteriaWithListValue;
	protected List criteriaWithBetweenValue;

	public Criteria(){
		criteriaWithoutValue=new ArrayList();
		criteriaWithSingleValue=new ArrayList();
		criteriaWithListValue=new ArrayList();
		criteriaWithBetweenValue=new ArrayList();
	}

	public boolean isValid() {
		return criteriaWithoutValue.size() > 0
				|| criteriaWithSingleValue.size() > 0
				|| criteriaWithListValue.size() > 0
				|| criteriaWithBetweenValue.size() > 0;
	}

	public List getCriteriaWithoutValue() {
		return criteriaWithoutValue;
	}

	public List getCriteriaWithSingleValue() {
		return criteriaWithSingleValue;
	}

	public List getCriteriaWithListValue() {
		return criteriaWithListValue;
	}

	public List getCriteriaWithBetweenValue() {
		return criteriaWithBetweenValue;
	}

	protected void addCriterion(String condition) {
		if (condition == null) {
			throw new RuntimeException("Value for condition cannot be null");
		}
		criteriaWithoutValue.add(condition);
	}

	protected void addCriterion(String condition, Object value,
			String property) {
		if (value == null) {
			throw new RuntimeException("Value for " + property
					+ " cannot be null");
		}
		Map map = new HashMap();
		map.put("condition", condition);
		map.put("value", value);
		criteriaWithSingleValue.add(map);
	}

	protected void addCriterion(String condition, List values,
			String property) {
		if (values == null || values.size() == 0) {
			throw new RuntimeException("Value list for " + property
					+ " cannot be null or empty");
		}
		Map map = new HashMap();
		map.put("condition", condition);
		map.put("values", values);
		criteriaWithListValue.add(map);
	}

	protected void addCriterion(String condition, Object value1,
			Object value2, String property) {
		if (value1 == null || value2 == null) {
			throw new RuntimeException("Between values for " + property
					+ " cannot be null");
		}
		List list = new ArrayList();
		list.add(value1);
		list.add(value2);
		Map map = new HashMap();
		map.put("condition", condition);
		map.put("values", list);
		criteriaWithBetweenValue.add(map);
	}


}
